<template>
    <rx-dialog @ok="handOk" @cancel="closeWindow" :okText="i18n('withdrawList.withdrawBtn','撤回')" :btnAlign="'center'">
        <rx-fit>
            <template #middle>
                <div style="height:100%;width:100%;padding:20px;">
                    <a-form :rules="rules" :model="form" ref="form" layout="vertical" class="rx-a-form-vertical">
                        <a-form-item :label="i18n('withdrawList.title','标题')">
                            {{ bpmInst.subject }}
                        </a-form-item>
                        <a-form-item :label="i18n('withdrawList.opinion','意见')" name="opinion">
                            <a-textarea v-model:value="form.opinion"
                                        :placeholder="i18n('withdrawList.opinion','请填写意见','write')"></a-textarea>
                        </a-form-item>
                    </a-form>
                </div>
            </template>
        </rx-fit>
    </rx-dialog>
</template>
<script>
import {RxDialog, Util, RxFit} from '@lowcode/jpaas-base-lib'
import BpmInstApi from '@/common/api/bpm/bpmInst'

export default {
    name: 'bpm-task-back',
    components: {
        RxFit,
        RxDialog,
    },
    props: {
        layerid: String,
        destroy: Function,
        //流程实例对象
        bpmInst: {
            type: Object
        },
        //来自页面
        from: String
    },
    data() {
        return {
            labelCol: {span: 4},
            wrapperCol: {span: 8},
            nextJumpType: 'normal',
            opinion: "",
            rules: {
                opinion: [
                    {required: true, message: this.i18n('withdrawList.opRequired', '意见必填'), trigger: 'blur'},
                    {
                        type: "string",
                        max: 300,
                        message: this.i18n('withdrawList.opLength', '长度不能大于300字符'),
                        trigger: 'blur'
                    },
                ]
            },
            form: {
                opinion: ""
            }
        }
    },
    created() {

    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmInst", key);
        },
        handOk(vm) {
            let self_ = this;
            vm.loading = true;
            this.$refs.form.validate().then(() => {
                BpmInstApi.revokeProcess(self_.bpmInst.instId, self_.form.opinion, this.from).then(res => {
                    vm.loading = false;
                    if (res.success) {
                        Util.closeWindow(self_, 'ok')
                    }
                });
            }).catch((error) => {
                vm.loading = false;
            })
        },
        closeWindow() {
            Util.closeWindow(this, 'cancel')
        }
    }
}
</script>
